package com.weixin.generic.test;

import java.util.*;

/**
 * @ClassName Dao
 * @date 2022/2/17 9:35
 * @author: wx
 * @Version 1.0
 */
public class Dao<T> {
    private Map<String, T> map = new HashMap<>();

    //save-method
    public void save(String id, T entity) {
        map.put(id, entity);
    }

    //get-method
    public T get(String id) {
        return map.get(id);
    }

    //update-method
    public void update(String id, T entity) {
        map.put(id, entity);
    }

    //list<T>-method
    public List<T> list() {
        List<T> list = new ArrayList<>();
        Set<String> strings = map.keySet();
        for (String key : strings) {
            System.out.println(key);
        }
        Collection<T> values = map.values();
        Iterator<T> iterator = values.iterator();
        if (iterator.hasNext()) {
            list.add(iterator.next());
        }
        return list;
    }
}
